package org.kisekiproject.actions {

	/**
	 * An action pointing to an underlying function.
	 */
	public class Action {

		private var _object:Object;
		private var _name:String;
		private var _parameterDef:Array;

		/**
		 * Contrtuctor.
		 */
		public function Action(object:Object, name:String, parameterDef:Array) {
			_object=object;
			_name=name;
			_parameterDef=parameterDef;
		}

		/**
		 * Call the action.
		 */
		public function call(parameters:Object):void {
			var useParameters:Array=new Array();

			for each (var paramName:String in _parameterDef) {
				if (!parameters[paramName])
					throw new Error("parameter "+paramName+" missing");

				useParameters.push(parameters[paramName]);
			}

			var f:Function=_object[_name];
			f.apply(_object,useParameters);
		}
	}
}